package org.concepts.java.core.concurrency.synchronize;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

/**
 * 
 * 
 * 
 * @author vvvv
 *
 */
public class TestPerformance {

  /**
   * 
   */
  @Test
  public void testListConcurrency() {
    List<Integer> names = Collections
        .synchronizedList(new ArrayList<Integer>());
     names = new ArrayList<Integer>();

    int count = 1000000;
    long stNanoTm = System.nanoTime();
    addToList(names, 0, count);
    long edNanoTm = System.nanoTime();
    System.out.println("Count [" + names.size() + "] Average time ["
        + (edNanoTm - stNanoTm) / count + "] ns");

  }

  private void addToList(List<Integer> list, int start, int count) {
    for (int cnt = 0; cnt < count; cnt++) {
      list.add(start + cnt);
    }
  }

}
